package core
{
	import flash.system.Security;
	import flash.utils.Dictionary;
	
	import mx.utils.StringUtil;
	
	
	public class Configuration
	{	
		public static const IS_DEBUG:Boolean = false;
		
		public static const ENV:String = "cn";  /* A */
		
		private static var _socialID:String = "";
		
		public static function get socialID():String
		{
			return _socialID;
		}
		
		private static var _timestamp:String;
		
		public static function get timestamp():String
		{
			return _timestamp;
		}
		
		private static var _zipped:Boolean = false;
		
		public static function get zipped():Boolean
		{
			return _zipped;
		}
		
		private static var _locale:String = "cn";
		
		public static function get locale():String
		{
			return _locale;
		}
		
		private static var _version:String = "0.0";
		
		public static function get version():String
		{
			return _version;
		}
		
		public static var sid:String = "";
		
		private static var _configPath:String = "";
		
		public static function get configPath():String
		{
			return _configPath;
		}
		
		public static function get moduleDataPath():String
		{
			return configPath + "module/";
		}
		
		private static var _assetsPath:String = "";
		
		public static function get assetsPath():String
		{
			return _assetsPath;
		}
		
		private static var _modulePath:String = "";
		
		public static function get modulePath():String
		{
			return _modulePath;
		}
		
		private static var _fontBasePath:String = "";
		
		public static function get fontPath():String
		{
			return _fontBasePath + locale + "/Fonts.swf";
		}
		
		private static var _languageBasePath:String = "";
		
		public static function get languagePath():String
		{
			return _languageBasePath + locale + "/language.xml";
		}
		
		public static function get skinPath():String
		{
			return assetsPath + "skins/";
		}
		
		private static var _gatewayPath:String;
		
		public static function get gatewayPath():String
		{
			return _gatewayPath;
		}
		
		private static var services:*;
		
		public static function getService(key:String):String
		{
			return services.service.(@key == key);
		}
		
		private static var socialServices:*;
		
		public static function getSocialService(key:String):String
		{
			return socialServices.social.(@key == key);
		}
		
		private static var _gamePreloaderPath : String;
		
		public static function get gamePreloaderPath () : String 
		{
			return _gamePreloaderPath;
		}
		
		private static var _configs:Dictionary = new Dictionary(true);  /* XML */
		
		public static function get configs():Dictionary
		{
			return _configs;
		}
		
		public static function clearConfigs():void
		{
			_configs = null;
		}
		
		public static function initBasicConfig():void
		{
			if (IS_DEBUG) _zipped = false;
			
			if (IS_DEBUG) _locale = "cn";
			
			if (IS_DEBUG) _socialID = "1425209570";
			
			if (IS_DEBUG) _timestamp = "1305820800";
			
			if (IS_DEBUG) _version = "0.0.1";
			
			if (IS_DEBUG) sid = "bbkk1425209570"; //Jay's session id
			
			if (IS_DEBUG) _configPath = "../config/";
			
			if (IS_DEBUG) _gatewayPath = "http://cxsj-game-dev.break-media.com.cn/gateway.php"
			
			if (IS_DEBUG) _assetsPath = "../assets/";
			
			if (IS_DEBUG) _modulePath = "modules/";
			
			if (IS_DEBUG) _fontBasePath = "fonts/";
			
			if (IS_DEBUG) _languageBasePath = "../" + ENV + "languages/";
			
			if (IS_DEBUG) _gamePreloaderPath = "loading/{0}/game_loading.swf";
			_gamePreloaderPath = StringUtil.substitute(_gamePreloaderPath, locale);
			
			var crossdomain:String;
			if(IS_DEBUG) crossdomain = "";
			if (crossdomain)
			{
				var tempCD:Array = crossdomain.split(",");
				for each (var cd:String in tempCD)
				{
					Security.loadPolicyFile(cd);
				}
			}
		}
		
		public static function initialize(config:XML):void
		{				
			CONFIG::debugging
			{
				services = config.services.debug;
			}
			CONFIG::release
			{
				services = config.services.release;
			}		
			socialServices = config.social_services;
		}
	}
}





